home *** CD-ROM | disk | FTP | other *** search
-
-
- /****************************************************************************
- * INPUT.C - Version 1.0
- *
- * This module implements some keyboard input code
- *
- * from Persistence of Vision Raytracer
- * Copyright 1994 Persistence of Vision Team
- * Copyright 1994 Christopher J. Cason.
- *---------------------------------------------------------------------------
- * NOTICE: This source code file is provided so that users may experiment
- * with enhancements to POV-Ray and to port the software to platforms other
- * than those supported by the POV-Ray Team. There are strict rules under
- * which you are permitted to use this file. The rules are in the file
- * named POVLEGAL.DOC which should be distributed with this file. If
- * POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- * Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- * Forum. The latest version of POV-Ray may be found there as well.
- *
- * POV-Ray files may also be obtained from ftp.uwa.edu.au in pub/povray.
- *
- * This program was written in its entirety by Christopher J. Cason.
- * Its use is freely and permanently granted to the POV-Team and POV users
- * under the conditions specified in POVLEGAL.DOC.
- *
- * Author : C. J. Cason (cjcason@yarrow.wt.uwa.edu.au, CIS 100032,1644)
- *
- *****************************************************************************/
-
- #include <mem.h>
- #include <dos.h>
- #include <string.h>
- #include "help.h"
-
- unsigned in_0x09 = 0 ;
- unsigned in_0x15 = 0 ;
- unsigned in_0x16 = 0 ;
- unsigned running = 0 ;
- unsigned popped_up = 0 ;
- unsigned popdown = 0 ;
- unsigned scancode ;
- unsigned scanflag ;
- unsigned counter ;
- unsigned home ;
- void interrupt (*old0x09) (void) ;
- void interrupt (*old0x1c) (void) ;
- void interrupt (*old0x15) (void) ;
- void interrupt (*old0x16) (void) ;
-
- extern char *paste_ptr ;
- extern unsigned paste ;
- extern unsigned home_wanted ;
-
- /* codes for CR (0x32) and LF (0x24) replaced with code for RETURN key */
- char scancodes [128] =
- {
- 0x03, 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, /* 000 through 007 */
- 0x23, 0x17, 0x1C, 0x25, 0x26, 0x1C, 0x31, 0x18, /* 008 through 015 */
- 0x19, 0x10, 0x13, 0x1F, 0x14, 0x16, 0x2F, 0x11, /* 016 through 023 */
- 0x2D, 0x15, 0x2C, 0x01, 0x2B, 0x1B, 0x07, 0x0C, /* 024 through 031 */
- 0x39, 0x02, 0x28, 0x04, 0x05, 0x06, 0x08, 0x28, /* 032 through 039 */
- 0x0A, 0x0B, 0x09, 0x0D, 0x33, 0x0C, 0x34, 0x35, /* 040 through 047 */
- 0x0B, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, /* 048 through 055 */
- 0x09, 0x0A, 0x27, 0x28, 0x33, 0x0D, 0x34, 0x35, /* 056 through 063 */
- 0x03, 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, /* 064 through 071 */
- 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, /* 072 through 079 */
- 0x19, 0x10, 0x13, 0x1F, 0x14, 0x16, 0x2F, 0x11, /* 080 through 087 */
- 0x2D, 0x15, 0x2C, 0x1A, 0x2B, 0x1B, 0x07, 0x0C, /* 088 through 095 */
- 0x29, 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, /* 096 through 103 */
- 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, /* 104 through 111 */
- 0x19, 0x10, 0x13, 0x1F, 0x14, 0x16, 0x2F, 0x11, /* 112 through 119 */
- 0x2D, 0x15, 0x2C, 0x1A, 0x2B, 0x1B, 0x29, 0x00 /* 120 through 127 */
- } ;
-
- void popup (void) ;
- void new0x16 (void) ;
- void CS_old0x16 (void) ;
-
- /* hardware keyboard interrupt handler */
-
- void interrupt new0x09 (void)
- {
- char kb_ch ;
- /*char s [9] ;*/
- static char far *kb_flag = (char far *) MK_FP (0x40, 0x17) ;
- union REGS regs ;
-
- if (in_0x09++ == 0)
- {
- enable () ;
- if (running == 0 || popdown == 0)
- {
- kb_ch = inportb (0x60) ;
- /* sprintf (s, "%02x", kb_ch) ;
- *(char *) MK_FP (0xb800, 0) = s [0] ;
- *(char *) MK_FP (0xb800, 2) = s [1] ;*/
- if ((*kb_flag & scanflag) == scanflag && kb_ch == scancode)
- {
- paste = home = 0 ;
- if (running != 0 && popdown == 0)
- {
- /* this IS needed due to some el-wierdo bug in the BIOS ??? */
- /* symptom : system will wait until next keystroke pressed */
- /* it won't happen if we use bioskey (0x01) instead of (0x11) */
- /* but if we don't use (0x11) we don't get extended characters */
- /* the problem may be machine-specific */
- regs.h.ah = 0x05 ;
- regs.x.cx = 0 ;
- int86 (0x16, ®s, ®s) ;
- }
- if (!running)
- running++ ;
- else
- popdown++ ;
- disable () ;
- outportb (0x20, 0x20) ;
- in_0x09-- ;
- return ;
- }
- }
- }
- disable () ;
- (*old0x09) () ;
- disable () ;
- in_0x09-- ;
- }
-
- /* user timer interrupt (software). use to count down for delays */
-
- void interrupt new0x1c (void)
- {
- union REGS regs ;
-
- if (counter) counter-- ;
-
- if (running == 0 && paste)
- {
- regs.h.al = 0xff ;
- while (paste != 0 && regs.h.al != 1)
- {
- if (home)
- {
- regs.h.ah = 0x05 ;
- regs.x.cx = 0x4700 ; /* HOME */
- int86 (0x16, ®s, ®s) ;
- if (regs.h.al != 0x01) home-- ;
- continue ;
- }
- if (*paste_ptr < 0x80)
- {
- if (*paste_ptr == '\n') *paste_ptr = '\r' ;
- if (*paste_ptr == '\r' && home_wanted) home = home_wanted ;
- regs.h.ah = 0x05 ;
- regs.x.cx = *paste_ptr ;
- regs.x.cx |= (unsigned) scancodes [*paste_ptr] << 8 ;
- int86 (0x16, ®s, ®s) ;
- }
- if (regs.h.al != 0x01)
- {
- paste_ptr++ ;
- paste-- ;
- if (home)
- {
- regs.h.ah = 0x05 ;
- regs.x.cx = 0x4700 ; /* HOME */
- int86 (0x16, ®s, ®s) ;
- if (regs.h.al != 0x01) home = 0 ;
- }
- }
- }
- }
- (*old0x1c) () ;
- }
-
- void kbinit (void)
- {
- old0x09 = getvect (0x09) ;
- setvect (0x09, new0x09) ;
- *(unsigned long *) CS_old0x16 = (unsigned long) (old0x16 = getvect (0x16)) ;
- setvect (0x16, (void interrupt (*) (void)) new0x16) ;
- old0x1c = getvect (0x1c) ;
- setvect (0x1c, (void interrupt (*) (void)) new0x1c) ;
- }
-
- void deinit (void)
- {
- setvect (0x09, old0x09) ;
- setvect (0x16, old0x16) ;
- setvect (0x1c, old0x1c) ;
- }